package tut.collection.code;

public class SoccerPlayer {
	private String firstname;
	private String surname;

	public SoccerPlayer(String firstname, String surname) {
		this.firstname = firstname;
		this.surname = surname;
	}

	public String toString() {
		return surname + ", " + firstname;
	}

	public int hashCode() {
		return this.toString().hashCode();
	}

	public boolean equals(Object player) {
		// Check the object is valid and is of the correct class type
		if (player == null)
			return false;
		if (this.getClass() != player.getClass())
			return false;

		// It is now safe to cast to SoccerPlayer and compare the classes
		// data members
		String name = player.toString();
		return this.toString().equals(name);
	}
}
